﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WeChatParking.Core.BLL
{
    /// <summary>
    /// 配置信息
    /// </summary>
    public class SystemConfig
    {
        /// <summary>
        /// 获取系统配置项的值
        /// </summary>
        /// <param name="configType">配置项类型</param>
        /// <returns></returns>
        public static string GetConfigValue(Entity.Enums.SystemConfig configType)
        {
            using (var dbContext = Repository.DbContext.Create())
            {
                var entity = dbContext.GetList<Entity.System_config>(new { conf_code = configType.ToString() }, null, null, false).SingleOrDefault();
                return entity == null ? string.Empty : entity.conf_value;
            }
        }

        /// <summary>
        /// 更新系统配置项的值
        /// </summary>
        /// <param name="configType">配置项类型</param>
        /// <param name="configValue">配置项值</param>
        /// <returns></returns>
        public static bool UpdateConfigValue(Entity.Enums.SystemConfig configType, string configValue)
        {
            using (var dbContext = Repository.DbContext.Create())
            {
                var entity = dbContext.GetList<Entity.System_config>(new { conf_code = configType.ToString() }, null, null, false).SingleOrDefault();
                if (entity != null)
                {
                    entity.conf_value = configValue;
                    return dbContext.Update(entity);
                }
                return false;
            }
        }

     

        /// <summary>
        /// 是否企业微信
        /// </summary>
        public static bool IsQiyeWeixin
        {
            get
            {
                var val = GetConfigValue(Entity.Enums.SystemConfig.IsQiyeWeixin);
                return string.Equals(val, "1") || string.Equals(val, "true");
            }
        }
    }
}
